<?php

namespace App\Model;


use Illuminate\Http\Request;

class PearlOutput extends BaseModel
{
    protected $connection='mysql';
    protected $table = 'pearl_output';
    public $timestamps = false;
    protected $fillable = ['created_date','recharge_output','activity_output','give_output','exchange_output','today_output','today_consume','grand_total','now_pearl', 'growth_rate'];
    
    public function getRechargeOutputAttribute($value){
        return number_format($value);
    }
    
    public function getExchangeOutputAttribute($value){
        return number_format($value);
    }
    
    public function getGiveOutputAttribute($value){
        return number_format($value);
    }
    
    public function getTodayOutputAttribute($value){
        return number_format($value);
    }
    
    public function getTodayConsumeAttribute($value){
        return number_format($value);
    }
    
    public function getGrandTotalAttribute($value){
        return number_format($value);
    }
    
    public function getNowDiamondAttribute($value){
        return number_format($value);
    }
    
    public function getList(Request $request){
        $limit = $request->input('limit', 10);
        $page = $request->input('page', 1);
        $begin_date = $request->input('begin_date');
        $end_date = $request->input('end_date');
    
        $query = new self();
    
        if($begin_date && $end_date) $query = $query->whereBetween('created_date',[ $begin_date, $end_date ]);
        if($begin_date && !$end_date) $query = $query->where('created_date', '>=', $begin_date);
        if(!$begin_date && $end_date) $query = $query->where('created_date', '<=', $end_date);

        return $query->orderBy('id','DESC')->paginate($limit,['*'],'page',$page);
    }
}
